/**
 * 战机对象
 * */
//单例设置模式
const Fighter=(function(){
	function Fighter(){
		Role.call(this,{
			width:66,
			height:80,
			x:100,
			y:100
		});
		this.element=$("#self");
	};
	//继承role.js
	Fighter.prototype=Object.create(Role.prototype);
	
	//战机移动
	Fighter.prototype.move=function(x,y){
		this.x=x-this.width/2;
		this.y=y-this.height/2;
		//判断战机移动是否超出地图
		if(this.x<=0){
			this.x=0
		}
		if(this.x>=(Map.width-this.width)){
			this.x=Map.width-this.width;
		}
		if(this.y<=0){
			this.y=0;
		}
		if(this.y>=(Map.height-this.height)){
			this.y=Map.height-this.height;
		}
		
		//css
		this.element.style.left=this.x+"px";
		this.element.style.top=this.y+"px";
		
	}
	//返回new Fighter
	//饿汉式
	return new Fighter();


	//懒汉式
//	let instance=null;
//	return{
//		getInstance:function(){
//			if(instance==null){
//				instance=new Fighter();
//			}
//			return instance;
//		}
//	}
})();
//Fighter.getInstance();
